package com.lzj.demo.dto;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonValue;
import com.lzj.demo.enums.GradeEnum;
import com.lzj.demo.enums.SexEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.LocalDateTypeHandler;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("student")
public class Student {
    @Id
    @TableId(value = "id", type = IdType.AUTO)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    /**
     * 姓名
     * */
    private String name;
    /**
     * 年龄
     * */
    private Integer age;
    /**
     * 性别，IEnum接口的枚举处理
     * 数据库字段：sex INT(3)
     */
    @EnumValue
    private SexEnum sex;
//    @EnumValue
//    @JsonValue
//    private final String sexDesc;
    /**
     * 年级，原生枚举（带{@link com.baomidou.mybatisplus.annotation.EnumValue}):
     * 数据库字段：grade INT(2)
     */
    @EnumValue
    private GradeEnum grade;
//    @EnumValue
//    @JsonValue
//    private final String gradeDesc;
    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    /**
     * 创建人
     */
    @TableField(fill = FieldFill.INSERT)
    private String createBy;
    /**
     * 修改时间
     */
    @TableField(value="modify_time", typeHandler = LocalDateTypeHandler.class, fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime modifyTime;
    /**
     * 修改人
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String modifyBy;
    /**
     * 是否可用 10-可用 20-删除
     */
    @TableLogic
    private Integer enableFlag;

    public Student(Long id, String name, Integer age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }
}
